//
// Created by denglibin on 2021/6/3.
//
#include "sub_scene.h"
#include "global.h"
/**
 * 事件处理
 * @param gameWindow
 */
static void handleEvent(SubScene* subScene);
/**
 * 创建
 * @param gameWindow
 * @return
 */
SubScene * SubSceneCreate(GameWindow* gameWindow){
    SubScene * subScene = (SubScene*) malloc(sizeof (SubScene));
    subScene->gameWindow = gameWindow;
    return subScene;
}

/**
 * 绘制
 * @param subScene
 */
void SubSceneDraw(SubScene* subScene){
    if(subScene == NULL || subScene->gameWindow == NULL){
        return;
    }
    handleEvent(subScene);
    //设置渲染器颜色
    SDL_SetRenderDrawColor(subScene->gameWindow->winRender, 0, 128, 128, 255);
    SDL_RenderClear(subScene->gameWindow->winRender); //用设置的颜色清除
    SDL_SetRenderDrawBlendMode(subScene->gameWindow->winRender, SDL_BLENDMODE_BLEND);//设置混合模式，支持alpha透明

    //生效
    SDL_RenderPresent(subScene->gameWindow->winRender);
    SDL_ShowWindow(subScene->gameWindow->win);
}

/**
 * 释放资源
 * @param subScene
 */
void SubSceneFree(SubScene* subScene){
    free(subScene);
}

/**
 * 事件处理
 * @param gameWindow
 */
void handleEvent(SubScene* subScene){
    while (SDL_PollEvent(&(subScene->gameWindow->event))){
        GlobalHandleEvent(subScene->gameWindow);
    }
}